<?php defined('SYSPATH') or die('No direct script access.');

class Model_Base extends Model
{
	protected function add($table, $info)
	{
		$columms = array();
		$values  = array();
		foreach ($info as $c => $v) 
		{
			$columms[] = $c;
			$values[]  = $v;
		}
		$query = DB::insert($table, $columms)->values($values);
		return $query->execute();
	}

	
	protected function edit($table, $id, $info)
	{
		$query = DB::update($table)->set($info)->where('id', '=', $id);
		return $query->execute();
	}
	
	protected function edit_two_required_field($table, $param1, $param2, $info)
	{
		$query = DB::update($table)->set($info)->where(key($param1), '=', $param1)->and_where(key($param2), '=', $param2);
		return $query->execute();
	}
    
	protected function edit_user($table, $user_id, $info)
	{
		$query = DB::update($table)->set($info)->where('user_id', '=', $user_id);
		//echo Debug::dump((string) $query, 1000);
		return $query->execute();
        
	}
}